//import java.sql.SQLException;
//import java.util.Calendar;
//import java.util.Date;
//
//
//public class conxion {
//	public static void main(String args[]) throws SQLException {
//		
////		try {
////			DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
////			Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@172.20.1.52:1521:orcl", "consulta_inspec", "consulta");
////			Statement stmt = conn.createStatement();
////			System.out.println("CONECTADO");
////			
////			
////			ResultSet rs = stmt.executeQuery("select sysdate from dual");
////			rs.next();
////			String fecha = rs.getString(1);
////			System.out.println(fecha);
////			stmt.close();
////			
////		} catch (Exception e) {
////			System.out.println("ERRRORORORO"+e.getLocalizedMessage());
////		}
////		
////		Date date = new Date();
////		Calendar calendar = Calendar.getInstance();
////	    calendar.setTime(date);
////		calendar.set(Calendar.HOUR_OF_DAY, 0);
////	    calendar.set(Calendar.MINUTE, 0);
////	    calendar.set(Calendar.SECOND, 0);
////	    calendar.set(Calendar.MILLISECOND, 0);
////		date = calendar.getTime();
//		
//	}
//
//}

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import javax.swing.JLabel;

public class conxion
{
    static List<JLabel> listOfLabels = new ArrayList<JLabel>();

    @SuppressWarnings("unchecked")
    public static void main(String[] args)
    {
        listOfLabels.add(new JLabel("Maria"));
        listOfLabels.add(new JLabel("Juan"));
        listOfLabels.add(new JLabel("Ana"));

        System.out.println("Before:");
        for(JLabel label: listOfLabels)
        {
            System.out.println(label.getText());
        }

        Collections.sort(listOfLabels, new LabelComparator1());

        System.out.println("After:");
        for(JLabel label: listOfLabels)
        {
            System.out.println(label.getText());
        }

    }

    static class LabelComparator implements Comparator {
        public int compare(Object obj1, Object obj2)
        {
            // Get labels
            JLabel label1 = (JLabel) obj1;
            JLabel label2 = (JLabel) obj2;

            // Get text
            String[] label1Text = label1.getText().split("-");
            String[] label2Text = label2.getText().split("-");

            // Convert to integers
            int label1Value = Integer.parseInt(label1Text[0]);
            int label2Value = Integer.parseInt(label2Text[0]);

            // Compare values
            if (label1Value > label2Value)
            {
                return 1;
            }
            else if (label1Value < label2Value)
            {
                return -1;
            }
            else
            {
                return 0;
            }
        }
    }
    
    static class LabelComparator1 implements Comparator {
        public int compare(Object obj1, Object obj2)
        {
            // Get labels
        	 JLabel label1 = (JLabel) obj1;
             JLabel label2 = (JLabel) obj2;

            // Get text
            String label1Text = label1.getText();
            String label2Text = label2.getText();

            // Compare values
            if (label1Text.compareTo(label2Text) > 0)
            {
                return 1;
            }
            else if (label1Text.compareTo(label2Text) < 0)
            {
                return -1;
            }
            else
            {
                return 0;
            }
        }
    }
}
